<script setup>

import { ref } from 'vue'
import httpUtils from '@/utils/http'

const empName = ref('')
const age = ref('')
const sex = ref('')
const email = ref('')

const onSubmit = () => {
    httpUtils.post('/emp/add', {
        empName: empName.value,
        age: age.value,
        sex: sex.value,
        email: email.value
    }).then(res => {
        console.log(res)
        location.href = '/index'
    }).catch(err => {
        console.log(err)
    })
}
</script>

<template>

    <form @submit.prevent="onSubmit">
        <div>
            <label for="name">名称：</label>
            <input id="name" v-model="empName" required />
        </div>
        <div>
            <label for="desc">年龄：</label>
            <input id="desc" v-model="age" required />
        </div>
        <div>
            <label for="sex">性别：</label>
            <input id="sex" v-model="sex" required />
        </div>
        <div>
            <label for="email">邮箱：</label>
            <input id="email" v-model="email" required />
        </div>
        <button type="submit">新&nbsp增</button>
    </form>
</template>


<style scoped>
div {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
}

label {
    width: 60px;
    font-weight: bold;
    color: #333;
    margin-right: 10px;
}

input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 15px;
    transition: border-color 0.2s;
}

input:focus {
    border-color: #409eff;
    outline: none;
}

button {
    background: #409eff;
    color: #fff;
    border: none;
    padding: 8px 28px;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover {
    background: #66b1ff;
}
</style>